import {observable,action} from 'mobx'
//解决用户刷新，数据应该存在session和状态库中
import {getSessionStorage,setSessionStorage} from '../util/storage'
import navList from '../route/navList'
class UserStore {
    @observable userMessage = getSessionStorage('userMessage') || {isLogin:false,permissions:''}
    @action
    loginServer = ()=>{
        return new Promise((resolve, reject) => {
            //发起请求
            resolve('登录成功')
        }).then(resp=>{
            let user1 = {
                isLogin:true,
                permissions:'user1',
                navUrl:navList['user1'],
            }
            // let user2 = {
            //     isLogin:true,
            //     permissions:'user2',
            //     navUrl:navList['usr2'],
            // }
            // let admin = {
            //     isLogin:true,
            //     permissions:'admin',
            //     navUrl:navList['admin'],
            // }
            console.log(user1)
            this.userMessage = {...user1}//登录成功，将用户信息存在观察仓库中
            setSessionStorage('userMessage',user1)//登录成功，将用户信息存在本地
        })
    }
    @action
    loginOut = ()=>{
        return new Promise((resolve, reject) =>{
            this.userMessage = {isLogin:false,permissions:''}
            setSessionStorage('userMessage','')
            resolve('退出登录')
        })
    }
}
export default UserStore